package com.hxh.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.hxh.dao.UserDao;
import com.hxh.entity.User;
import com.hxh.entity.input.UserInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
@Slf4j
public class UserService {
    @Resource UserDao userDao;


    public boolean insert(UserInput pojo) {

        boolean res = userDao.insert(pojo) > 0;

        return res;
    }

    public int insertList(List<UserInput> pojo) {
        if(CollectionUtils.isEmpty(pojo)){
            return 0;
        }

        int res = userDao.insertList(pojo);
        return res;
    }

    public List<User> select(UserInput pojo) {
        return userDao.select(pojo);
    }

    public boolean deleteById(Integer id){
        return userDao.deleteById(id) > 0;
    }

    public User selectById(Integer id){
        if(id == null ) {
          return null;
        }
        return userDao.selectById(id);
    }

    public void listPage(Page<User> page, UserInput pojo) {
        page.setRecords(userDao.listPage(page, pojo));
    }

    public boolean update(UserInput pojo) {

        boolean res = userDao.update(pojo) > 0;

        return res;
    }

    public boolean updateSelective(UserInput pojo) {

        int res = userDao.updateSelective(pojo);
        return res > 0;
    }

    public void updateByKey(UserInput userInput) {
        userDao.updateByKey(userInput);
    }
}
